"""
    两个栈实现队列,完成队列的push()和pop()操作
"""


class Solution:
    def __init__(self):
        self.stack1 = []
        self.stack2 = []

    def push(self, item):
        """
        入队
        """
        self.stack1.append(item)

    def pop(self):
        """
        出队操作
        """
        # stack1 : [100,200,300]
        # stack2 : []
        if self.stack2:
            return self.stack2.pop()

        if not self.stack1:
            raise Exception("pop from empty queue")

        while self.stack1:
            self.stack2.append(self.stack1.pop())

        # 出队
        return self.stack2.pop()


if __name__ == '__main__':
    s = Solution()
    s.push(100)
    s.push(200)
    s.push(300)
    # 终端: 100 200 300 异常
    print(s.pop())
    print(s.pop())
    print(s.pop())
    print(s.pop())

















